# -*- coding: utf-8 -*-
"""
@Time: 2021/12/10 13:19
@Author: jins
@File: table_upowerd.py
@Introduction: upowerd表造数据
"""

from common.mysqlDataOperate import OperateMysql
import random
from datetime import datetime, timedelta

EfficacyOptions_list = [1, 2]
PhaseOptions_list = [1, 2, 4, 8, 16]
combination_list = [(i, j) for i in EfficacyOptions_list for j in PhaseOptions_list]


def insert(start):
    op = OperateMysql()
    for j in range(start + 1, start + 3):
        for k in combination_list:
            data_time_origin = datetime(2021, 11, 1, 0, 0, 0)
            fmt = '%Y%m%d'
            for i in range(30):
                unit_id = 10000000 + j
                data_time = data_time_origin.strftime(fmt)
                increase_num = random.uniform(5.0, 10.0)
                MaxValue = random.uniform(3000.0, 5000.0)
                MinValue = random.uniform(500.0, 1000.0)
                AvgValue = random.uniform(2000.0, 3000.0)
                MaxMinDiff = random.uniform(1000.0, 1200.0)
                MaxMinDiffRatio = MaxMinDiff / AvgValue
                AvgRatio = random.uniform(0.1, 0.5)
                UpdateTime = data_time_origin.timestamp()*1000
                sql = f"""INSERT INTO xlcloud.upowerd21b
                VALUES
                    (   
                        {unit_id},
                        1,
                        {(data_time_origin + timedelta(hours=9)).strftime(fmt)},
                        {k[0]},
                        {k[1]},
                        {MaxValue},
                        {data_time},
                        {MinValue},
                        {(data_time_origin + timedelta(hours=12)).strftime(fmt)},
                        {AvgValue},
                        {MaxMinDiff},
                        {MaxMinDiffRatio},
                        {AvgRatio},
                        6,
                        0,
                        {UpdateTime}
                    )
                        """
                op.batch_excute(sql)
                data_time_origin += timedelta(days=1)
            op.commit()
    op.close()


if __name__ == '__main__':
    insert(0)
